<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 1、导入mapbox的依赖 -->
    <script src='https://api.mapbox.com/mapbox-gl-js/v2.15.0/mapbox-gl.js'></script>
    <link href='https://api.mapbox.com/mapbox-gl-js/v2.15.0/mapbox-gl.css' rel='stylesheet' />
    <style>
        * {
            margin: 0;
            padding: 0
        }

        #map {
            width: 100vw;
            height: 100vh;
        }
    </style>
</head>

<body>
    <!-- 2、设置地图容器的挂载点 -->
    <div id="map">

    </div>
    <script>
        /* token */
        mapboxgl.accessToken = 'pk.eyJ1IjoiZXJpYzA5MTciLCJhIjoiY2x3cTI2Zzg0MWY2dDJqcWVpdDI1MHNpcCJ9.k9gLW7ZgLyISNdYHIEEGdQ'
        const map = new mapboxgl.Map({
            /* target-ol */
            container: 'map', // container ID
            /* style-layers */
            style: 'mapbox://styles/mapbox/streets-v12', // style URL
            center: [114.40088809833583,
                30.4663210497187], // starting position [lng, lat]
            zoom: 15, // starting zoom
            pitch: 70
        });
        let data = 'http://39.103.151.139:8000/gis/zhongdi'
        map.on("style.load", () => {
            map.addSource("zhongdi-source", {
                type: "geojson",
                data
            })
            map.addLayer({
                id: "zhongdi-layer",
                source: "zhongdi-source",
                type: "fill-extrusion",
                paint: {
                    // 'fill-extrusion-height': 200,
                    /* 可以获取geojson中properties的值 */
                    'fill-extrusion-height': 100,
                    'fill-extrusion-opacity': 0.5,
                    'fill-extrusion-color': "#652e80"
                }
            })
        })
        map.on("click", () => {
            // console.log(map)
            var height = map.getPaintProperty("zhongdi-layer", "fill-extrusion-height")
            height += 10;
            map.setPaintProperty("zhongdi-layer", "fill-extrusion-height", height)
        })
    </script>
</body>

</html>